// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class ALLERGY_RSP_Z88 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("22 AL1",22)]
  	    [HL7Field(HL7Version.v24, 22, HL7Repeat.True, HL7Required.True,"AL1")]
	    public AL1[] AL1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("24 VISIT",24)]
  	    [HL7Field(HL7Version.v24, 24, HL7Repeat.False, HL7Required.False,"VISIT_RSP_Z88")]
	    public VISIT_RSP_Z88 VISIT {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			AL1 = PopSegmentParseAndCheckRequiredArray<AL1>(availableData, options, "AL1");
			VISIT = ProcessGroup<VISIT_RSP_Z88>(availableData, options, "VISIT");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isAL1 = availableData.StartsWith("AL1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("AL1", options.Version) || isAL1) {
				return isAL1;
			}
			VISIT_RSP_Z88 testVISIT_RSP_Z88 = new VISIT_RSP_Z88();
			bool grpCCVISIT_RSP_Z88 = (testVISIT_RSP_Z88.CanConsume(availableData, options));
			if (IsRequired("VISIT", options.Version) || grpCCVISIT_RSP_Z88) {
				return grpCCVISIT_RSP_Z88;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "ALLERGY";
			}
        }

        static ALLERGY_RSP_Z88() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(ALLERGY_RSP_Z88));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (AL1 != null && AL1.Length > 0) {
			for (int i = 0; i < AL1.Length; i++) {
				string segmentValue = AL1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (VISIT != null) {
			string segmentValue = VISIT.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

